package com.yf.ea;

/*
    标量替换(分离对象)测试
    -Xms100m -Xmx100m -XX:+DoEscapeAnalysis -XX:+PrintGC -XX:-EliminateAllocations

    -XX:-EliminateAllocations 不开启标量替换
 */
public class ScalarReplace {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        for (int i = 0; i < 10000000; i++) {
            alloc();
        }

        long end = System.currentTimeMillis();
        System.out.println("花费时间为：" + (end - start) + " ms");

    }

    public static class User {
        public int id;
        public String name;
    }

    public static void alloc() {
        User u = new User();
        u.id = 5;
        u.name = "yvan";
    }
}
